package org.one.stone.soup.grfxML.plugin.function;


import org.one.stone.soup.grfxML.GrfxMLEngine;
import org.one.stone.soup.grfxML.plugin.SimplePlugin;
import org.one.stone.soup.grfxML.plugin.grfxMLCaster;
import org.one.stone.soup.math.IntMath;
import org.one.stone.soup.mjdb.data.field.DataLinker;
import org.one.stone.soup.mjdb.data.field.Field;
import org.one.stone.soup.mjdb.data.field.LockException;

public class PointToSize extends SimplePlugin {


	public static final int ARG_POINT = 0;

	public static final int ARG_SIZE = 1;



	org.one.stone.soup.grfxML.DataPoint point = new org.one.stone.soup.grfxML.DataPoint();
	org.one.stone.soup.grfxML.DataSize size = new org.one.stone.soup.grfxML.DataSize();
	private int currentX;
	private int currentY;

/**
 * StateInverter constructor comment.
 */
public PointToSize(GrfxMLEngine engine){
	super(engine);
}
/**
 * initialize method comment.
 */
public void initialize()
{
 try{
	currentX = point.getValueX();
	currentY = point.getValueY();
	size.setValue(IntMath.distance(currentX,currentY),this);
 }catch(LockException le){}
}
/**
 * process method comment.
 */
public void process()
{
	try{
		if(currentX!=point.getValueX() || currentY!=point.getValueY())
		{
			currentX=point.getValueX();
			currentY=point.getValueY();
			size.setValue(IntMath.distance(currentX,currentY),this);
		}
	}catch(LockException le){}
}
/**
 * register method comment.
 */
public void register(DataLinker store)
{

	point = grfxMLCaster.cast(point,getArg(point,ARG_POINT,store));

	size = grfxMLCaster.cast(size,getArg(size,ARG_SIZE,store));

}
/**
 * replace method comment.
 */
public void replace(Field oldObj, Field newObj)
{

	point = grfxMLCaster.replace(point,oldObj,newObj);

	size = grfxMLCaster.replace(size,oldObj,newObj);

}
/**
 * stop method comment.
 */
public void stop() {}
}
